import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { RandomPropRendererInfo } from "./info/RandomPropRendererInfo";
import { ItemData } from "../../resource/info/ItemData";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { ImagesConst } from "../../resource/ImagesConst";
import { BaseItem } from "../common/BaseItem";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { Language } from "../../../../extend/language/Language";
import { TodayNotTipUtil } from "../../../common/TodayNotTipUtil";
import { TodayNoTipsConst } from "../../../component/gconst/TodayNoTipsConst";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ERandItemType } from "../../../../Message/Public/ERandItemType";
import { NumInput } from "../common/NumInput";
import { GButton } from "../../../../com/mui/controls/GButton";
import { _ERandItemJewel } from "../../../../ERandItemType/_ERandItemJewel";
import { _propItemData } from "../../../../this/_propItemData";
type int = number;
//class RandomPropCellRenderer
    
    export  class RandomPropCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public set isOverlay(arg1: Boolean)
        {
            this._isOverlay = arg1;
            if (arg1) 
            {
                this._nameTxt.y = 5;
                this._itemBg.y = 25;
                if (!this._numInput) 
                {
                    this._numInput = ObjCreate.createNumInput(20, 95, this);
                    this._numInput.addEventListener(flash.events.Event.CHANGE, this.onNumChangeHandler);
                }
                if (!this.contains(this._numInput)) 
                {
                    this.addChild(this._numInput);
                }
            }
            else 
            {
                this._nameTxt.y = 90;
                this._itemBg.y = 15;
                if (this._numInput && this.contains(this._numInput)) 
                {
                    this.removeChild(this._numInput);
                }
            }
            this._baseItem.y = this._itemBg.y + 4;
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (typeof arg1 === "randomproprendererinfo") 
            {
                this._randomPropRendererInfo = arg1 as RandomPropRendererInfo;
                this._propItemData = this._randomPropRendererInfo.itemData;
                this._itemData = new ItemData(this._randomPropRendererInfo.itemCode);
                this._baseItem.itemData = this._itemData;
                this._nameTxt.htmlText = ItemsUtil.getItemName(this._itemData);
                this.isOverlay = this._randomPropRendererInfo.amount > 1;
                if (this._numInput) 
                {
                    this._numInput.maxNum = this._randomPropRendererInfo.amount;
                }
            }
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 120, 140, this);
            this._itemBg = ObjCreate.createBg(26, 25, 68, 68, this, ImagesConst.PackItemBg);
            this._baseItem = new BaseItem();
            this._baseItem.setSize(60, 60);
            this._baseItem.x = this._itemBg.x + 4;
            this._baseItem.y = this._itemBg.y + 4;
            this._baseItem.setAmountLabelPos(0, 45);
            this.addChild(this._baseItem);
            this._nameTxt = ObjCreate.createTextField("", 0, 5, 120, 50, this, new GTextFormat(FontUtil.songtiName, 12, 16711935, true));
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._getBtn = ObjCreate.createGButton(Language.getString(55106), 20, 113, 80, 24, this);
            this._getBtn.drawNow();
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            return;
        }

        /* internal  */onNumChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            arg1.stopPropagation();
            return;
        }

        /* internal  */get useAmout(): int
        {
            if (this._isOverlay) 
            {
                return this._numInput.currentNum;
            }
            return 1;
        }

        /* internal  */onGetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            var loc2=null;
            if (this._propItemData && this._itemData) 
            {
                loc1 = this.useAmout;
                loc2 = Language.getStringByParam(55107, loc1, ItemsUtil.getItemName(this._propItemData), loc1, ItemsUtil.getItemName(this._itemData));
                TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.RandomPropGemNotTip, this.useRequest, loc2, null, Alert.OK | Alert.CANCEL);
            }
            return;
        }

        /* internal  */useRequest(): void
        {
            var loc1=new Map<any, any> /* flash.utils.Dictionary */();
            loc1[this._randomPropRendererInfo.itemCode] = this.useAmout;
            Dispatcher.dispatchEvent(new DataEvent(EventName.RandomPropUseItem, {"randType": _ERandItemJewel, "itemData": _propItemData, "uidItemDict": loc1}));
            return;
        }

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_itemBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_numInput: NumInput;

        /* internal */ /* var */_getBtn: GButton;

        /* internal */ /* var */_randomPropRendererInfo: RandomPropRendererInfo;

        /* internal */ /* var */_propItemData: ItemData;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_isOverlay: Boolean;
    }
